package util;

import java.io.File;
import java.io.FileInputStream;

/**
 * @author xxyWi
 */
public class MyClassLoader extends ClassLoader  {
    @Override
    public Class<?> findClass(String classPath, String name) {
        String myPath = classPath + "\\" + name.replace(".", "\\") + ".class";
        System.out.println(myPath);
        File f = new File(myPath);
        FileInputStream file = null;
        try {
            file = new FileInputStream(f);
            byte[] b = new byte[(int) f.length()];
            file.read(b);
            Class c = findLoadedClass(name);
            if (c == null) {
                Class c2 = defineClass(name, b, 0, b.length);
                resolveClass(c2);
                return c2;
            }
            return c;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
